<?php
/**
 * @Author: king
 * @Date:   2019-01-18 23:29:03
 * @Last Modified by:   king
 * @Last Modified time: 2019-01-21 21:45:28
 */
namespace App\Tools\Astrolog;


class Synastry
{
    /**
     * 参数配置
     * @var array
     */
    public $option = [
        'recode1' => [],
        'recode2' => [],
        'data1' => [],
        'data2' => [],
    ];
    /**
     * 内置其他参数配置
     * @var array
     * base 每颗星设定合盘计分比重值如下太阳80，月亮110，水星50，金星60，火星50，上升80，中天70；共500
     */
    protected $param = [
        'base' => [0 => 80, 1 => 110, 2 => 50, 3 => 60, 4 => 50, ASC => 80, MC => 70],
    ];
    /**
     * 当前生成的数据
     * @var array
     */
    public $data = [
        'coef1' => [],
        'coef2' => [],
        'score' => [
            'attract' => 0,
            'chat' => 0,
            'passion' => 0,
            'benefit' => 0,
            'happy' => 0,
            'probTobeLover' => 0,
        ],
        'harmoniousConflict' => [0, 0],
    ];
    /**
     * 错误信息 msg
     * @var string
     */
    protected $error = '';

    /**
     * 构造函数
     * AuthenticateLove constructor.
     * @param array $option 自定义配置
     */
    public function __construct($option = [])
    {
        // 实例化时初始化参数
        if (!empty($option))
        {
            $this->option = array_merge($this->option, $option);
        }
    }

    public function init()
    {
        if (empty($this->option['data1']) || empty($this->option['data2']) || empty($this->option['recode1']) || empty($this->option['recode2']))
        {
            $this->error = '基础参数错误：synastry';
            return false;
        }

        $this->data['coef1'] = $this->getThePrimingScore($this->option['data1']);
        $this->data['coef2'] = $this->getThePrimingScore($this->option['data2']);
        $this->getTheHarmoniousAndConflict();

        $attract = $this->getTheAttractScore();// 吸引指数
        $chat = $this->getTheChatScore();// 沟通指数
        $passion = $this->getThePassionScore();// 激情指数
        $benefit = $this->getTheintimateScore();// 亲密指数
        $happy = $this->getTheHappyScore();// 愉悦指数
        $probTobeLover = $this->getTheProbTobeLover();// 缘分指数
        $attract = ($attract / 200 * 100);
        $chat = ($chat / 120 * 100);
        $passion = ($passion / 180 * 100);
        $benefit = ($benefit / 120 * 100);
        $happy = ($happy / 130 * 100);
        $probTobeLover = ($probTobeLover / 180 * 100);
        $this->data['score']['attract'] = $attract > 100 ? 100 : ($attract < 1 ? 1 : round($attract));
        $this->data['score']['chat'] = $chat > 100 ? 100 : ($chat < 1 ? 1 : round($chat));
        $this->data['score']['passion'] = $passion > 100 ? 100 : ($passion < 1 ? 1 : round($passion));
        $this->data['score']['benefit'] = $benefit > 100 ? 100 : ($benefit < 1 ? 1 : round($benefit));
        $this->data['score']['happy'] = $happy > 100 ? 100 : ($happy < 1 ? 1 : round($happy));
        $this->data['score']['probTobeLover'] = $probTobeLover > 100 ? 100 : ($probTobeLover < 1 ? 1 : round($probTobeLover));

        return [];
    }

    /**
     * 获取个人星正反引动指数 日月水金火木土天海冥
     * 木土天海冥北交相位对象只计算日月水金火四轴
     * 有相位系数(使用中)
     * @param array $data
     * @return array
     */
    protected function getThePrimingScore($data = [])
    {
        $ret = ['obverse' => [], 'versa' => []];
        $imp_o = [0 => 14, 1 => 15, 2 => 8, 3 => 10, 4 => 9, 5 => 7.5, 6 => 3, 7 => 5, 8 => 5, 9 => 4, 12 => 4, ASC => 14, MC => 13];// 重要指数=》正
        $imp_v = [0 => 14, 1 => 15, 2 => 8, 3 => 10, 4 => 9, 5 => 7.5, 6 => 15, 7 => 5, 8 => 5, 9 => 4, 12 => 4, ASC => 14, MC => 13];// 重要指数=》反
        $b = $data[1];// b用户
        $planets = $b['planets'];
        foreach ($planets as $i => $p)
        {
            if ($i > 12 && $i != ASC && $i != MC) continue;
            $ret['obverse'][$i] = $ret['versa'][$i] = 0;

            if (empty($p['phase'])) continue;// 空相时结束本轮循环

            foreach ($p['phase'] as $phase)
            {
                $k = $phase['id'];
                $phase_e = $phase['phase_e'];
                $phase_orb = $phase['phase_orb'];
                $coef_o = 0;// 正面系数
                $coef_v = 0;// 反面系数
//                $phase_o = 0;// 相位系数
                if ($phase_orb < 0.5) $phase_o = 1;
                elseif ($phase_orb < 1.5) $phase_o = 0.9;
                elseif ($phase_orb < 3) $phase_o = 0.85;
                elseif ($phase_orb <= 5) $phase_o = 0.8;
                else $phase_o = 0.75;

                if (in_array($k, [0, 1, 2, 3, 5]))
                {
                    if ($phase_e == 0) $coef_o = 1;
                    elseif ($phase_e == 60) $coef_o = 0.7;
                    elseif ($phase_e == 120) $coef_o = 0.85;
                    elseif ($phase_e == 90)
                    {
                        $coef_o = 0.2;
                        $coef_v = 0.8;
                    } elseif ($phase_e == 180)
                    {
                        $coef_o = 0.7;
                        $coef_v = 0.5;
                    }
                    $ret['obverse'][$i] += $imp_o[$k] * $coef_o * $phase_o;
                    $ret['versa'][$i] += $imp_v[$k] * $coef_v * $phase_o;
                } elseif ($k == 4 || $k == 6)
                {
                    if ($phase_e == 0)
                    {
                        $coef_o = 1;
                        $coef_v = 0.5;
                        if ($k == 4)
                        {
                            $coef_o = 0.5;
                            $coef_v = 0.8;
                        }
                    } elseif ($phase_e == 60)
                    {
                        $coef_o = 0.7;
                        $coef_v = 0.2;
                    } elseif ($phase_e == 90)
                    {
                        $coef_o = 0.2;
                        $coef_v = 0.9;
                    } elseif ($phase_e == 120)
                    {
                        $coef_o = 0.8;
                        $coef_v = 0.2;
                    } elseif ($phase_e == 180)
                    {
                        $coef_o = 0.7;
                        $coef_v = 0.7;
                    }
                    $ret['obverse'][$i] += $imp_o[$k] * $coef_o * $phase_o;
                    if ($k == 6) $ret['versa'][$i] += $imp_v[$k] * $coef_v * $phase_o;
                    else $ret['versa'][$i] += $imp_v[$k] * $coef_v * $phase_o;
                } elseif (in_array($i, [0, 1, 2, 3, 4, ASC, MC]) && in_array($k, [7, 8, 9]))
                {
                    if ($phase_e == 0)
                    {
                        $coef_o = 1;
                        $coef_v = 0.5;
                    } elseif ($phase_e == 60)
                    {
                        $coef_o = 0.7;
                        $coef_v = 0.2;
                    } elseif ($phase_e == 90)
                    {
                        $coef_o = 0.2;
                        $coef_v = 0.9;
                    } elseif ($phase_e == 120)
                    {
                        $coef_o = 0.8;
                        $coef_v = 0.2;
                    } elseif ($phase_e == 180)
                    {
                        $coef_o = 0.7;
                        $coef_v = 0.7;
                    }
                    $ret['obverse'][$i] += $imp_o[$k] * $coef_o * $phase_o;
                    $ret['versa'][$i] += $imp_v[$k] * $coef_v * $phase_o;
                } // 北交点
                elseif (in_array($i, [0, 1, 2, 3, 4, ASC, MC]) && $k == 12)
                {
                    if ($phase_e == 0) $coef_o = 1;
                    elseif ($phase_e == 60) $coef_o = 0.7;
                    elseif ($phase_e == 90) $coef_o = 0.7;
                    elseif ($phase_e == 120) $coef_o = 0.7;
                    elseif ($phase_e == 180) $coef_o = 1;
                    $ret['obverse'][$i] += $imp_o[$k] * $coef_o * $phase_o;

                } elseif ($k == ASC || $k == MC)
                {
                    if ($phase_e == 0) $coef_o = 1;
                    elseif ($phase_e == 60) $coef_o = 0.6;
                    elseif ($phase_e == 90)
                    {
                        $coef_o = 0.2;
                        $coef_v = 0.8;
                    } elseif ($phase_e == 120) $coef_o = 0.65;
                    elseif ($phase_e == 180) $coef_o = 0.9;
                    $ret['obverse'][$i] += $imp_o[$k] * $coef_o * $phase_o;
                    $ret['versa'][$i] += $imp_v[$k] * $coef_v * $phase_o;
                }
            }
        }
        return $ret;
    }

    /**
     * 获取阴阳系数
     * 有日月分别合轴则以日月拱论；有金火分别合轴则以金火拱论
     * @return array [日月阴阳系数,金火阴阳系数]
     */
    protected function getTheYinyangScore()
    {
        $ret = [0, 0];
//        $a = $data->details1;// a用户底盘
        $b = $this->option['data2'];// b用户
        $planets = $b['planets'];
        // 日月阴阳系数
        if (isset($planets[0]['phase']['0-1']))
        {
            $phase = $planets[0]['phase']['0-1']['phase_e'];
            if (
                (
                    (isset($planets[0]['phase']['0-' . ASC]) && in_array($planets[0]['phase']['0-' . ASC]['phase_e'], [0, 180]))
                    || (isset($planets[0]['phase']['0-' . MC]) && in_array($planets[0]['phase']['0-' . MC]['phase_e'], [0, 180]))
                )
                && (
                    (isset($planets[1]['phase']['1-' . ASC]) && in_array($planets[1]['phase']['1-' . ASC]['phase_e'], [0, 180]))
                    || (isset($planets[1]['phase']['1-' . MC]) && in_array($planets[1]['phase']['1-' . MC]['phase_e'], [0, 180]))
                )
            )
            {
                $phase = 120;
            }
            if ($phase == 0) $ret[0] = 1;
            elseif ($phase == 60) $ret[0] = 0.8;
            elseif ($phase == 90) $ret[0] = 0.4;
            elseif ($phase == 120) $ret[0] = 0.9;
            elseif ($phase == 180) $ret[0] = 0.7;
        }
        // 金火阴阳系数
        if (isset($planets[3]['phase']['3-4']))
        {
            $phase = $planets[3]['phase']['3-4']['phase_e'];
            if (
                (
                    (isset($planets[3]['phase']['3-' . ASC]) && in_array($planets[3]['phase']['3-' . ASC]['phase_e'], [0, 180]))
                    || (isset($planets[3]['phase']['3-' . MC]) && in_array($planets[3]['phase']['3-' . MC]['phase_e'], [0, 180]))
                )
                && (
                    (isset($planets[4]['phase']['4-' . ASC]) && in_array($planets[4]['phase']['4-' . ASC]['phase_e'], [0, 180]))
                    || (isset($planets[4]['phase']['4-' . MC]) && in_array($planets[4]['phase']['4-' . MC]['phase_e'], [0, 180]))
                )
            )
            {
                $phase = 120;
            }
            if ($phase == 0) $ret[1] = 1;
            elseif ($phase == 60) $ret[1] = 0.8;
            elseif ($phase == 90) $ret[1] = 0.4;
            elseif ($phase == 120) $ret[1] = 0.9;
            elseif ($phase == 180) $ret[1] = 0.7;
        }
        return $ret;
    }

    /**
     * 吸引指数
     * 基数=金星正指数-金星负指数
     * 1、若存在日月、金火非刑相，每有一组则+50*相位系数*容许度系数（相位系数：合1，拱0.85，六分0.75，冲0.9）；
     * 2、若一方火星刑对方金星，其金星也刑对方火星，或其金星与对分月亮或太阳合拱六分，此时若其金星无刑相位且不与土星成相，+36；
     * 3、若一方太阳或月亮进入对方的5或7宫，每有一个+15
     * ##########4、一方金星若与对方土星刑冲，-35
     * 4、若一方太阳或月亮与对方上升或下降相合，每有一个+20
     * 5、若一方太阳或月亮与对方天顶或天底相合，每有一个+15
     * @return int
     */
    protected function getTheAttractScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];

        $ret += ($coef1['obverse'][3] + $coef2['obverse'][3]) - ($coef1['versa'][3] + $coef2['versa'][3]);

        $planets1 = $this->option['data1'][1]['planets'];// 外圈数据B
        $planets2 = $this->option['data2'][1]['planets'];// 外圈数据A
        $phase_e = $phase_o = 0;
        // 若存在日月、金火非刑相，每有一组则+50*相位系数*容许度系数（相位系数：合1，拱0.85，六分0.75，冲0.9）；
        // 日月
        if (isset($planets1[0]['phase']['0-1']) && $planets1[0]['phase']['0-1']['phase_e'] != 90)
        {
            $_e = $planets1[0]['phase']['0-1']['phase_e'];
            $_orb = $planets1[0]['phase']['0-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            elseif ($_orb > 5) $phase_o = 0.75;
            $ret += 50 * $phase_e * $phase_o;
        }
        // 月日
        if (isset($planets1[1]['phase']['1-0']) && $planets1[1]['phase']['1-0']['phase_e'] != 90)
        {
            $_e = $planets1[1]['phase']['1-0']['phase_e'];
            $_orb = $planets1[1]['phase']['1-0']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            elseif ($_orb > 5) $phase_o = 0.75;
            $ret += 50 * $phase_e * $phase_o;
        }
        // 金火
        if (isset($planets1[3]['phase']['3-4']) && $planets1[3]['phase']['3-4']['phase_e'] != 90)
        {
            $_e = $planets1[3]['phase']['3-4']['phase_e'];
            $_orb = $planets1[3]['phase']['3-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            elseif ($_orb > 5) $phase_o = 0.75;
            $ret += 50 * $phase_e * $phase_o;
        }
        // 火金
        if (isset($planets2[3]['phase']['3-4']) && $planets2[3]['phase']['3-4']['phase_e'] != 90)
        {
            $_e = $planets2[3]['phase']['3-4']['phase_e'];
            $_orb = $planets2[3]['phase']['3-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            elseif ($_orb > 5) $phase_o = 0.75;
            $ret += 50 * $phase_e * $phase_o;
        }
        // 若一方火星刑对方金星，其金星也刑对方火星，或其金星与月亮或太阳合拱六分，此时若其金星无刑相位且不与土星成相，+36；
        if (isset($planets1[4]['phase']['4-3']) && $planets1[4]['phase']['4-3']['phase_e'] == 90
            && (
                (isset($planets1[3]['phase']['3-4']) && $planets1[3]['phase']['3-4']['phase_e'] == 90)
                || (isset($planets1[3]['phase']['3-0']) && in_array($planets1[3]['phase']['3-0']['phase_e'], [0, 60, 120]))
                || (isset($planets1[3]['phase']['3-1']) && in_array($planets1[3]['phase']['3-1']['phase_e'], [0, 60, 120]))
            ) && !isset($planets1[3]['phase']['3-6'])
        )
        {
            $venu_phase90_num = 0;
            foreach ($planets1[3]['phase'] as $ph)
            {
                if ($ph['phase_e'] == 90) $venu_phase90_num++;
            }
            if ($venu_phase90_num == 0) $ret += 36;
        }
        if (isset($planets2[4]['phase']['4-3']) && $planets2[4]['phase']['4-3']['phase_e'] == 90
            && (
                (isset($planets2[3]['phase']['3-4']) && $planets2[3]['phase']['3-4']['phase_e'] == 90)
                || (isset($planets2[3]['phase']['3-0']) && in_array($planets2[3]['phase']['3-0']['phase_e'], [0, 60, 120]))
                || (isset($planets2[3]['phase']['3-1']) && in_array($planets2[3]['phase']['3-1']['phase_e'], [0, 60, 120]))
            ) && !isset($planets2[3]['phase']['3-6'])
        )
        {
            $venu_phase90_num = 0;
            foreach ($planets2[3]['phase'] as $ph)
            {
                if ($ph['phase_e'] == 90) $venu_phase90_num++;
            }
            if ($venu_phase90_num == 0) $ret += 36;
        }
        // 若一方太阳或月亮进入对方的5或7宫，每有一个+20
        if (in_array($planets1[0]['in_house_id'], [5, 7]))
        {
            $ret += 20;
        }
        if (in_array($planets1[1]['in_house_id'], [5, 7]))
        {
            $ret += 20;
        }
        if (in_array($planets2[0]['in_house_id'], [5, 7]))
        {
            $ret += 20;
        }
        if (in_array($planets2[1]['in_house_id'], [5, 7]))
        {
            $ret += 20;
        }
        // 若一方金火进入对方的5或7宫，每有一个+15
        if (in_array($planets1[3]['in_house_id'], [5, 7]))
        {
            $ret += 15;
        }
        if (in_array($planets1[4]['in_house_id'], [5, 7]))
        {
            $ret += 15;
        }
        if (in_array($planets2[3]['in_house_id'], [5, 7]))
        {
            $ret += 15;
        }
        if (in_array($planets2[4]['in_house_id'], [5, 7]))
        {
            $ret += 15;
        }
        // 一方金星若与对方土星刑冲，-35
        if (isset($planets1[3]['phase']['3-6']) && in_array($planets1[3]['phase']['3-6']['phase_e'], [90, 180]))
        {
            $ret -= 35;
        }
        if (isset($planets1[6]['phase']['6-3']) && in_array($planets1[6]['phase']['6-3']['phase_e'], [90, 180]))
        {
            $ret -= 35;
        }
        // 月亮与对方土星刑冲-40  去掉  20180119 by gks

        // 若存在日月金火之间的冲相位，每个+8
        for ($i = 0; $i < 5; $i++)
        {
            if ($i == 2) continue;
            for ($j = 0; $j < 5; $j++)
            {
                if ($j == 2 || $j < $i) continue;

                if (isset($planets1[$i]['phase'][$i . '-' . $j]) && $planets1[$i]['phase'][$i . '-' . $j]['phase_e'] == 180)
                {
                    $ret += 8;
                }
                if (isset($planets2[$i]['phase'][$i . '-' . $j]) && $planets2[$i]['phase'][$i . '-' . $j]['phase_e'] == 180)
                {
                    $ret += 8;
                }
            }
        }
        // 若有一方日月金火之一与对方日月金水火木两颗以上成非刑相，+6*x（x为相位个数，多个类似情况只计分一次,按相位多的记分）
        $t_o = [];
        for ($i = 0; $i < 5; $i++)
        {
            if ($i == 2) continue;
            $x1 = 0;
            $x2 = 0;
            for ($j = 0; $j < 6; $j++)
            {
                if (isset($planets1[$i]['phase'][$i . '-' . $j]) && $planets1[$i]['phase'][$i . '-' . $j]['phase_e'] != 90)
                {
                    $x1++;
                }
                if (isset($planets2[$i]['phase'][$i . '-' . $j]) && $planets2[$i]['phase'][$i . '-' . $j]['phase_e'] != 90)
                {
                    $x2++;
                }
            }
            if ($x1 > 2) $t_o[] = $x1;
            if ($x2 > 2) $t_o[] = $x2;
        }
        if (count($t_o) > 0)
        {
            $ret += (max($t_o) * 6);
        }

        // 若一方太阳或月亮与对方上升或下降相合，每有一个+20
        // 日升
        if (isset($planets1[0]['phase']['0-' . ASC]) && in_array($planets1[0]['phase']['0-' . ASC]['phase_e'], [0, 180]))
        {
            $ret += 20;
        }
        // 升日
        if (isset($planets1[ASC]['phase'][ASC . '-0']) && in_array($planets1[ASC]['phase'][ASC . '-0']['phase_e'], [0, 180]))
        {
            $ret += 20;
        }
        // 月升
        if (isset($planets1[1]['phase']['1-' . ASC]) && in_array($planets1[1]['phase']['1-' . ASC]['phase_e'], [0, 180]))
        {
            $ret += 20;
        }
        // 升月
        if (isset($planets1[ASC]['phase'][ASC . '-1']) && in_array($planets1[ASC]['phase'][ASC . '-1']['phase_e'], [0, 180]))
        {
            $ret += 20;
        }
        // 若一方太阳或月亮与对方天顶或天底相合，每有一个+15
        // 日顶
        if (isset($planets1[0]['phase']['0-' . MC]) && in_array($planets1[0]['phase']['0-' . MC]['phase_e'], [0, 180]))
        {
            $ret += 15;
        }
        // 顶日
        if (isset($planets1[MC]['phase'][MC . '-0']) && in_array($planets1[MC]['phase'][MC . '-0']['phase_e'], [0, 180]))
        {
            $ret += 15;
        }
        // 月顶
        if (isset($planets1[1]['phase']['1-' . MC]) && in_array($planets1[1]['phase']['1-' . MC]['phase_e'], [0, 180]))
        {
            $ret += 15;
        }
        // 顶月
        if (isset($planets1[MC]['phase'][MC . '-1']) && in_array($planets1[MC]['phase'][MC . '-1']['phase_e'], [0, 180]))
        {
            $ret += 15;
        }

        return $ret;
    }

    /**
     * 前缘指数
     * 基数=北交点正指数*2+海王星正指数+冥王星正指数
     * @return int
     */
    protected function getTheFateScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];

        $ret += ($coef1['obverse'][12] + $coef2['obverse'][12]) * 2
            + $coef1['obverse'][8] + $coef2['obverse'][8]
            + $coef1['obverse'][9] + $coef2['obverse'][9];
        return $ret;
    }

    /**
     * 沟通指数
     * 基数=月亮正指数+水星正指数-水星负指数-月亮负指数
     * #######若双方水星有且只有与对方月、水、日、金、木、上升、中天的合拱六分相，+35；######
     * #######若双方月亮有且只有与对方月、水、日、金、木、上升、中天的合拱六分相，+50；######
     * 若双方水星都有与对方月、水、日、金、木的合拱六分相，且无刑冲相位，也无火、土相位，则加35
     * 若双方月亮都有与对方月、水、日、金、木的合拱六分相，且无刑冲相位，也无火、土相位，则加50
     * @return int
     */
    protected function getTheChatScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];

//        $ret += $coef1['obverse'][1] + $coef2['obverse'][1]
//            + $coef1['obverse'][2] + $coef2['obverse'][2]
//            - $coef1['versa'][1] - $coef2['versa'][1] - $coef1['versa'][2] - $coef2['versa'][2];
//        $ret += ($coef1['obverse'][2] + $coef2['obverse'][2]) * 1.5 + ($coef1['obverse'][1] + $coef2['obverse'][1]) * 0.5;
        $housePower = $this->getTheHousePower();// 宫位能量  0 正 | 1 负
//        沟通=30+水正-水负+9正-9负+3正-3负
        $ret += 30 + ($coef1['obverse'][2] + $coef2['obverse'][2]) - $coef1['versa'][2] - $coef2['versa'][2]
            + $housePower[0][9] - $housePower[1][9] + $housePower[0][3] - $housePower[1][3];

        $planets1 = $this->option['data1'][1]['planets'];
        $planets2 = $this->option['data2'][1]['planets'];
        // 双方月亮无与火星土星天王海王冥王的合刑冲，且无与日月金水的刑相位，且至少有一个与日月金木的合拱六分相
        if (
            (!isset($planets1[1]['phase']['1-4']) || !in_array($planets1[1]['phase']['1-4']['phase_e'], [0, 90, 180]))
            && (!isset($planets1[1]['phase']['1-6']) || !in_array($planets1[1]['phase']['1-6']['phase_e'], [0, 90, 180]))
            && (!isset($planets1[1]['phase']['1-7']) || !in_array($planets1[1]['phase']['1-7']['phase_e'], [0, 90, 180]))
            && (!isset($planets1[1]['phase']['1-8']) || !in_array($planets1[1]['phase']['1-8']['phase_e'], [0, 90, 180]))
            && (!isset($planets1[1]['phase']['1-9']) || !in_array($planets1[1]['phase']['1-9']['phase_e'], [0, 90, 180]))
            && (!isset($planets2[1]['phase']['1-4']) || !in_array($planets2[1]['phase']['1-4']['phase_e'], [0, 90, 180]))
            && (!isset($planets2[1]['phase']['1-6']) || !in_array($planets2[1]['phase']['1-6']['phase_e'], [0, 90, 180]))
            && (!isset($planets2[1]['phase']['1-7']) || !in_array($planets2[1]['phase']['1-7']['phase_e'], [0, 90, 180]))
            && (!isset($planets2[1]['phase']['1-8']) || !in_array($planets2[1]['phase']['1-8']['phase_e'], [0, 90, 180]))
            && (!isset($planets2[1]['phase']['1-9']) || !in_array($planets2[1]['phase']['1-9']['phase_e'], [0, 90, 180]))
            && (!isset($planets1[1]['phase']['1-0']) || $planets1[1]['phase']['1-0']['phase_e'] != 90)
            && (!isset($planets1[1]['phase']['1-1']) || $planets1[1]['phase']['1-1']['phase_e'] != 90)
            && (!isset($planets1[1]['phase']['1-2']) || $planets1[1]['phase']['1-2']['phase_e'] != 90)
            && (!isset($planets1[1]['phase']['1-3']) || $planets1[1]['phase']['1-3']['phase_e'] != 90)
            && (!isset($planets2[1]['phase']['1-0']) || $planets2[1]['phase']['1-0']['phase_e'] != 90)
            && (!isset($planets2[1]['phase']['1-2']) || $planets2[1]['phase']['1-2']['phase_e'] != 90)
            && (!isset($planets2[1]['phase']['1-3']) || $planets2[1]['phase']['1-3']['phase_e'] != 90)
            &&
            (
                (isset($planets1[1]['phase']['1-0']) && in_array($planets1[1]['phase']['1-0']['phase_e'], [0, 60, 120]))
                || (isset($planets1[1]['phase']['1-1']) && in_array($planets1[1]['phase']['1-1']['phase_e'], [0, 60, 120]))
                || (isset($planets1[1]['phase']['1-3']) && in_array($planets1[1]['phase']['1-3']['phase_e'], [0, 60, 120]))
                || (isset($planets1[1]['phase']['1-5']) && in_array($planets1[1]['phase']['1-5']['phase_e'], [0, 60, 120]))
            )
            &&
            (
                (isset($planets2[1]['phase']['1-0']) && in_array($planets2[1]['phase']['1-0']['phase_e'], [0, 60, 120]))
                || (isset($planets2[1]['phase']['1-1']) && in_array($planets2[1]['phase']['1-1']['phase_e'], [0, 60, 120]))
                || (isset($planets2[1]['phase']['1-3']) && in_array($planets2[1]['phase']['1-3']['phase_e'], [0, 60, 120]))
                || (isset($planets2[1]['phase']['1-5']) && in_array($planets2[1]['phase']['1-5']['phase_e'], [0, 60, 120]))
            )
        )
        {
            $ret += 50;
        }

        $merc1_phase_b = [0, 0];
        if (!empty($planets1[2]['phase']))
        {
            foreach ($planets1[2]['phase'] as $merc1_phase)
            {
                if ($merc1_phase['id'] > 9 || $merc1_phase['id'] < ASC) continue;
                if (in_array($merc1_phase['phase_e'], [0, 60, 120]))
                {

                    if (in_array($merc1_phase['id'], [0, 1, 2, 3, 5]))
                    {
                        $merc1_phase_b[0]++;
                    } else
                    {
                        $merc1_phase_b[1]++;
                    }
                }
                if (in_array($merc1_phase['phase_e'], [90, 180]))
                {
                    $merc1_phase_b[1]++;
                }
            }
        }
        $merc2_phase_b = [0, 0];
        if (!empty($planets2[2]['phase']))
        {
            foreach ($planets2[2]['phase'] as $merc2_phase)
            {
                if ($merc2_phase['id'] > 9 || $merc2_phase['id'] < ASC) continue;
                if (in_array($merc2_phase['phase_e'], [0, 60, 120]))
                {

                    if (in_array($merc2_phase['id'], [0, 1, 2, 3, 5]))
                    {
                        $merc2_phase_b[0]++;
                    } else
                    {
                        $merc2_phase_b[1]++;
                    }
                }
                if (in_array($merc2_phase['phase_e'], [90, 180]))
                {
                    $merc2_phase_b[1]++;
                }
            }
        }
        if ($merc1_phase_b[0] && !$merc1_phase_b[1] && $merc2_phase_b[0] && !$merc2_phase_b[1])
        {
            $ret += 35;
        }
        // 若双方水星均与对方木星或月亮成合拱六分相，+25
        if (
            (
                isset($planets1[2]['phase']['2-1']) && in_array($planets1[2]['phase']['2-1']['phase_e'], [0, 60, 120])
                || isset($planets1[2]['phase']['2-5']) && in_array($planets1[2]['phase']['2-5']['phase_e'], [0, 60, 120])
            )
            &&
            (
                isset($planets2[2]['phase']['2-1']) && in_array($planets2[2]['phase']['2-1']['phase_e'], [0, 60, 120])
                || isset($planets2[2]['phase']['2-5']) && in_array($planets2[2]['phase']['2-5']['phase_e'], [0, 60, 120])
            )
        )
        {
            $ret += 25;
        }

//        若双方水星互相刑-15；
        if (isset($planets1[2]['phase']['2-2']) && $planets1[2]['phase']['2-2']['phase_e'] == 90)
        {
            $ret -= 15;
        }
//        若一方水星与另一方土星刑冲-15；
        if (
            (isset($planets1[2]['phase']['2-6']) && in_array($planets1[2]['phase']['2-6']['phase_e'], [90, 180]))
            || (isset($planets2[2]['phase']['2-6']) && in_array($planets2[2]['phase']['2-6']['phase_e'], [90, 180]))
        )
        {
            $ret -= 15;
        }
//        若一方水星与另一方月亮刑-18；
        if (
            (isset($planets1[2]['phase']['2-1']) && $planets1[2]['phase']['2-1']['phase_e'] == 90)
            || (isset($planets2[2]['phase']['2-1']) && $planets2[2]['phase']['2-1']['phase_e'] == 90)
        )
        {
            $ret -= 18;
        }
//        若一方水星与另一方月亮对冲-12；
        if (
            (isset($planets1[2]['phase']['2-1']) && $planets1[2]['phase']['2-1']['phase_e'] == 180)
            || (isset($planets2[2]['phase']['2-1']) && $planets2[2]['phase']['2-1']['phase_e'] == 180)
        )
        {
            $ret -= 12;
        }
//        若一方水星与另一方火星刑冲-12；
        if (
            (isset($planets1[2]['phase']['2-4']) && in_array($planets1[2]['phase']['2-4']['phase_e'], [90, 180]))
            || (isset($planets2[2]['phase']['2-4']) && in_array($planets2[2]['phase']['2-4']['phase_e'], [90, 180]))
        )
        {
            $ret -= 12;
        }
//        若一方水星与另一方太阳刑-13；
        if (
            (isset($planets1[2]['phase']['2-0']) && $planets1[2]['phase']['2-0']['phase_e'] == 90)
            || (isset($planets2[2]['phase']['2-0']) && $planets2[2]['phase']['2-0']['phase_e'] == 90)
        )
        {
            $ret -= 13;
        }
//        若一方水星与另一方太阳对冲-9；
        if (
            (isset($planets1[2]['phase']['2-0']) && $planets1[2]['phase']['2-0']['phase_e'] == 180)
            || (isset($planets2[2]['phase']['2-0']) && $planets2[2]['phase']['2-0']['phase_e'] == 180)
        )
        {
            $ret -= 9;
        }
//        若一方土星落对方3宫-10，若此时土星刑冲对方日月水，每个-10
        if (
            $planets1[6]['in_house_id'] == 3 || $planets2[6]['in_house_id'] == 3
        )
        {
            $ret -= 10;
            if ($planets1[6]['in_house_id'] == 3)
            {
                if (isset($planets1[6]['phase']['6-0']) && in_array($planets1[6]['phase']['6-0']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
                if (isset($planets1[6]['phase']['6-1']) && in_array($planets1[6]['phase']['6-1']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
                if (isset($planets1[6]['phase']['6-2']) && in_array($planets1[6]['phase']['6-2']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
            }
            if ($planets2[6]['in_house_id'] == 3)
            {
                if (isset($planets2[6]['phase']['6-0']) && in_array($planets2[6]['phase']['6-0']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
                if (isset($planets2[6]['phase']['6-1']) && in_array($planets2[6]['phase']['6-1']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
                if (isset($planets2[6]['phase']['6-2']) && in_array($planets2[6]['phase']['6-2']['phase_e'], [90, 180]))
                {
                    $ret -= 10;
                }
            }
        }

        return $ret;
    }

    /**
     * 激情指数
     * 基数=火星正指数
     * 若存在火金、火火非刑相，每个+40*相位系数*容许系数；
     * 若存在日火、月火非刑相，每个+20*相位系数*容许系数；
     * 若存在火星与土星的合刑冲相，每个-30*相位系数*容许系数；
     * @return int
     */
    protected function getThePassionScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];

        $planets1 = $this->option['data1'][1]['planets'];
        $planets2 = $this->option['data2'][1]['planets'];

        $ret += $coef1['obverse'][4] + $coef2['obverse'][4];
        $phase_e = 0;
        // 若存在火金、火火非刑相，每个+40*相位系数*容许系数；
        // 火金
        if (isset($planets1[4]['phase']['4-3']) && $planets1[4]['phase']['4-3']['phase_e'] != 90)
        {
            $_e = $planets1[4]['phase']['4-3']['phase_e'];
            $_orb = $planets1[4]['phase']['4-3']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 40 * $phase_e * $phase_o;
            // （若双方为一男一女，成相火星属于男方，则额外+20）
            if ($this->option['recode1']['type'] != 1 && $this->option['recode2']['type'] == 1)
            {
                $ret += 20;
            }
        }
        // 金火
        if (isset($planets1[3]['phase']['3-4']) && $planets1[3]['phase']['3-4']['phase_e'] != 90)
        {
            $_e = $planets1[3]['phase']['3-4']['phase_e'];
            $_orb = $planets1[3]['phase']['3-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 40 * $phase_e * $phase_o;
            // （若双方为一男一女，成相火星属于男方，则额外+20）
            if ($this->option['recode1']['type'] == 1 && $this->option['recode2']['type'] != 1)
            {
                $ret += 20;
            }
        }
        // 火火
        if (isset($planets1[4]['phase']['4-4']) && $planets1[4]['phase']['4-4']['phase_e'] != 90)
        {
            $_e = $planets1[4]['phase']['4-4']['phase_e'];
            $_orb = $planets1[4]['phase']['4-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 40 * $phase_e * $phase_o;
            // （若双方为一男一女，成相火星属于男方，则额外+20）
            if ($this->option['recode1']['type'] == 1 && $this->option['recode2']['type'] != 1)
            {
                $ret += 20;
            }
        }
        // 若存在日火、月火非刑相，每个+20*相位系数*容许系数；
        // 日火
        if (isset($planets1[0]['phase']['0-4']) && $planets1[0]['phase']['0-4']['phase_e'] != 90)
        {
            $_e = $planets1[0]['phase']['0-4']['phase_e'];
            $_orb = $planets1[0]['phase']['0-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 20 * $phase_e * $phase_o;
        }
        // 火日
        if (isset($planets1[4]['phase']['4-0']) && $planets1[4]['phase']['4-0']['phase_e'] != 90)
        {
            $_e = $planets1[4]['phase']['4-0']['phase_e'];
            $_orb = $planets1[4]['phase']['4-0']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 20 * $phase_e * $phase_o;
        }
        // 月火
        if (isset($planets1[1]['phase']['1-4']) && $planets1[1]['phase']['1-4']['phase_e'] != 90)
        {
            $_e = $planets1[1]['phase']['1-4']['phase_e'];
            $_orb = $planets1[1]['phase']['1-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 20 * $phase_e * $phase_o;
        }
        // 火月
        if (isset($planets1[4]['phase']['4-1']) && $planets1[4]['phase']['4-1']['phase_e'] != 90)
        {
            $_e = $planets1[4]['phase']['4-1']['phase_e'];
            $_orb = $planets1[4]['phase']['4-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret += 20 * $phase_e * $phase_o;
        }
        // 若存在火星与土星的合刑冲相，每个-30*相位系数*容许系数；
        // 火土
        if (isset($planets1[4]['phase']['4-6']) && in_array($planets1[4]['phase']['4-6']['phase_e'], [0, 90, 180]))
        {
            $_e = $planets1[4]['phase']['4-6']['phase_e'];
            $_orb = $planets1[4]['phase']['4-6']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret -= 30 * $phase_e * $phase_o;
        }
        // 土火
        if (isset($planets1[6]['phase']['6-4']) && in_array($planets1[6]['phase']['6-4']['phase_e'], [0, 90, 180]))
        {
            $_e = $planets1[6]['phase']['6-4']['phase_e'];
            $_orb = $planets1[6]['phase']['6-4']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 90) $phase_e = 0.8;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            if ($phase_e) $ret -= 30 * $phase_e * $phase_o;
        }
        // 若一方火星进入对方1/5/7宫，+10；若双方均如此，再加20
        if (in_array($planets1[4]['in_house_id'], [1, 5, 7]))
        {
            $ret += 10;
        }
        if (in_array($planets2[4]['in_house_id'], [1, 5, 7]))
        {
            $ret += 10;
        }
        if (in_array($planets1[4]['in_house_id'], [1, 5, 7]) && in_array($planets2[4]['in_house_id'], [1, 5, 7]))
        {
            $ret += 20;
        }
        return $ret;
    }

    /**
     * 长久指数
     * 基数=Asc+Mc的正指数合 + 太阳的正指数合 +月亮的正指数合+土星的正指数合-月亮的负指数合-太阳的负指数合-ASC的负指数合-MC的负指数合-天王星的负指数合；
     * 若天王星与轴点合相，每多一组*0.8；
     * @return float
     */
    protected function getThePermanentlyScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];

        $ret += $coef1['obverse'][ASC] + $coef2['obverse'][ASC] + $coef1['obverse'][MC] + $coef2['obverse'][MC]
            + $coef1['obverse'][0] + $coef2['obverse'][0] + $coef1['obverse'][1] + $coef2['obverse'][1]
            + $coef1['obverse'][6] + $coef2['obverse'][6]
            - $coef1['versa'][0] - $coef2['versa'][0] - $coef1['versa'][1] - $coef2['versa'][1]
            - $coef1['versa'][ASC] - $coef2['versa'][ASC] - $coef1['versa'][MC] - $coef2['versa'][MC]
            - $coef1['versa'][7] - $coef2['versa'][7];
        $planet1 = $this->option['data1'][1];
        $planet2 = $this->option['data2'][1];
        if (isset($planet1['planets'][7]['phase']['7-' . ASC]) && in_array($planet1['planets'][7]['phase']['7-' . ASC]['phase_e'], [0, 180]))
        {
            $ret *= 0.8;
        }
        if (isset($planet1['planets'][7]['phase']['7-' . MC]) && in_array($planet1['planets'][7]['phase']['7-' . MC]['phase_e'], [0, 180]))
        {
            $ret *= 0.8;
        }
        if (isset($planet2['planets'][7]['phase']['7-' . ASC]) && in_array($planet2['planets'][7]['phase']['7-' . ASC]['phase_e'], [0, 180]))
        {
            $ret *= 0.8;
        }
        if (isset($planet2['planets'][7]['phase']['7-' . MC]) && in_array($planet2['planets'][7]['phase']['7-' . MC]['phase_e'], [0, 180]))
        {
            $ret *= 0.8;
        }

        return $ret;
    }

    /**
     * 亲密指数
     * 基数=月亮正指数-月亮负指数
     * 若存在月合上升、日月合拱六分、月月合拱六分、月金合拱六分，每多一组则+30*相位系数*容许系数；
     * 若双方月亮都与对方日月金木之一成合拱六分，且除日月金水木上升中天的合拱六分外无其它相位，+50
     * @return float
     */
    protected function getTheintimateScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];
        $ret += $coef1['obverse'][1] + $coef2['obverse'][1] - $coef1['versa'][1] - $coef2['versa'][1];

        $planets1 = $this->option['data1'][1]['planets'];
        $planets2 = $this->option['data2'][1]['planets'];
        $phase_e = 0;
        // 若存在月合上升、日月合拱六分、月月合拱六分、月金合拱六分，每多一组则+30*相位系数*容许系数；
        // 月上升
        if (isset($planets1[1]['phase']['1-' . ASC]) && $planets1[1]['phase']['1-' . ASC]['phase_e'] == 0)
        {
            $_e = $planets1[1]['phase']['1-' . ASC]['phase_e'];
            $_orb = $planets1[1]['phase']['1-' . ASC]['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 上升月
        if (isset($planets1[ASC]['phase'][ASC . '-1']) && $planets1[ASC]['phase'][ASC . '-1']['phase_e'] == 0)
        {
            $_e = $planets1[ASC]['phase'][ASC . '-1']['phase_e'];
            $_orb = $planets1[ASC]['phase'][ASC . '-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 月月
        if (isset($planets1[1]['phase']['1-1']) && in_array($planets1[1]['phase']['1-1']['phase_e'], [0, 60, 120]))
        {
            $_e = $planets1[1]['phase']['1-1']['phase_e'];
            $_orb = $planets1[1]['phase']['1-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 日月
        if (isset($planets1[0]['phase']['0-1']) && in_array($planets1[0]['phase']['0-1']['phase_e'], [0, 60, 120]))
        {
            $_e = $planets1[0]['phase']['0-1']['phase_e'];
            $_orb = $planets1[0]['phase']['0-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 月日
        if (isset($planets1[1]['phase']['1-0']) && in_array($planets1[1]['phase']['1-0']['phase_e'], [0, 60, 120]))
        {
            $_e = $planets1[1]['phase']['1-0']['phase_e'];
            $_orb = $planets1[1]['phase']['1-0']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 月金
        if (isset($planets1[1]['phase']['1-3']) && in_array($planets1[1]['phase']['1-3']['phase_e'], [0, 60, 120]))
        {
            $_e = $planets1[1]['phase']['1-3']['phase_e'];
            $_orb = $planets1[1]['phase']['1-3']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 金月
        if (isset($planets1[3]['phase']['3-1']) && in_array($planets1[3]['phase']['3-1']['phase_e'], [0, 60, 120]))
        {
            $_e = $planets1[3]['phase']['3-1']['phase_e'];
            $_orb = $planets1[3]['phase']['3-1']['phase_orb'];
            if ($_e == 0) $phase_e = 1;
            elseif ($_e == 60) $phase_e = 0.75;
            elseif ($_e == 120) $phase_e = 0.85;
            elseif ($_e == 180) $phase_e = 0.9;
            if ($_orb < 0.5) $phase_o = 1;
            elseif ($_orb < 1.5) $phase_o = 0.9;
            elseif ($_orb < 3) $phase_o = 0.85;
            elseif ($_orb <= 5) $phase_o = 0.8;
            else $phase_o = 0.75;
            $ret += 30 * $phase_e * $phase_o;
        }
        // 若一方月亮是该星盘中与对方日月金水火四轴非刑相最多的星体且非刑相不少于3个，+25
        $foreach_list = [0, 1, 2, 3, 4, ASC, MC];
        $no_90_1 = $no_90_2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        for ($i = 0; $i < 10; $i++)
        {
            foreach ($foreach_list as $fl)
            {
                if (isset($planets1[$fl]['phase'][$fl . '-' . $i]) && $planets1[$fl]['phase'][$fl . '-' . $i]['phase_e'] != 90)
                {
                    $no_90_1[$i]++;
                }
                if (isset($planets2[$fl]['phase'][$fl . '-' . $i]) && $planets2[$fl]['phase'][$fl . '-' . $i]['phase_e'] != 90)
                {
                    $no_90_2[$i]++;
                }
            }
        }
        $max_90_num_1 = max($no_90_1);
        $max_90_num_2 = max($no_90_2);
        if (($max_90_num_1 >= 3 && $max_90_num_1 == $no_90_1[1]) || ($max_90_num_2 >= 3 && $max_90_num_2 == $no_90_2[1]))
        {
            $ret += 25;
        }
        // 若双方月亮在同一星座，亲密低于40者令其=40；
        // 若双方月亮在同象星座，亲密低于25者令其=25；
        // 若双方月亮均无月火土天刑冲相，亲密低于30者都令其=30
        if ($planets1[1]['in_sign_id'] == $planets2[1]['in_sign_id'] && $ret < 40)
        {
            $ret = 40;
        } elseif (
            (!isset($planets1[1]['phase']['1-1']) || !in_array($planets1[1]['phase']['1-1']['phase_e'], [90, 180]))
            && (!isset($planets1[1]['phase']['1-4']) || !in_array($planets1[1]['phase']['1-4']['phase_e'], [90, 180]))
            && (!isset($planets1[1]['phase']['1-6']) || !in_array($planets1[1]['phase']['1-6']['phase_e'], [90, 180]))
            && (!isset($planets1[1]['phase']['1-7']) || !in_array($planets1[1]['phase']['1-7']['phase_e'], [90, 180]))
            && (!isset($planets2[1]['phase']['1-1']) || !in_array($planets2[1]['phase']['1-1']['phase_e'], [90, 180]))
            && (!isset($planets2[1]['phase']['1-4']) || !in_array($planets2[1]['phase']['1-4']['phase_e'], [90, 180]))
            && (!isset($planets2[1]['phase']['1-6']) || !in_array($planets2[1]['phase']['1-6']['phase_e'], [90, 180]))
            && (!isset($planets2[1]['phase']['1-7']) || !in_array($planets2[1]['phase']['1-7']['phase_e'], [90, 180]))
            && $ret < 30
        )
        {
            $ret = 30;
        } elseif ($planets1[1]['in_sign_id'] % 4 == $planets2[1]['in_sign_id'] % 4 && $ret < 25)
        {
            $ret = 25;
        }

        return $ret;
    }

    /**
     * 愉悦指数
     * 基数=木星正指数+金星正指数+月亮正指数-金星负指数-月亮负指数
     * @return int
     */
    protected function getTheHappyScore()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];
        $ret += $coef1['obverse'][5] + $coef2['obverse'][5] + $coef1['obverse'][3] + $coef2['obverse'][3]
            + $coef1['obverse'][1] + $coef2['obverse'][1]
            - $coef1['versa'][1] - $coef2['versa'][1] - $coef1['versa'][3] - $coef2['versa'][3];

        return $ret;
    }

    /**
     * 缘分指数
     * #####基数=（A、M、日、月、金、水、火的正指数合+北交点正指数*3）*和谐度百分比
     * 基数=A、M的正指数合+北交点正指数*2
     * @return float|int
     */
    protected function getTheProbTobeLover()
    {
        $ret = 0;
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];
//        $hc = $this->getTheHarmoniousAndConflict($data1, $data2);
        $ret += (
            $coef1['obverse'][ASC] + $coef2['obverse'][ASC]
            + $coef1['obverse'][MC] + $coef2['obverse'][MC]
            + ($coef1['obverse'][12] + $coef2['obverse'][12]) * 2
        );

        return $ret;
    }

    /**
     * 获取行星和谐度和冲突度
     */
    protected function getTheHarmoniousAndConflict()
    {
        $ret = [0, 0];// 和谐度|冲突度
        $coef1 = $this->data['coef1'];
        $coef2 = $this->data['coef2'];
        $planets1 = $this->option['data1'][1]['planets'];
        $planets2 = $this->option['data2'][1]['planets'];
        $total = $coef1['obverse'][0] + $coef1['versa'][0] + $coef2['obverse'][0] + $coef2['versa'][0]
            + $coef1['obverse'][1] + $coef1['versa'][1] + $coef2['obverse'][1] + $coef2['versa'][1]
            + $coef1['obverse'][2] + $coef1['versa'][2] + $coef2['obverse'][2] + $coef2['versa'][2]
            + $coef1['obverse'][3] + $coef1['versa'][3] + $coef2['obverse'][3] + $coef2['versa'][3]
            + $coef1['obverse'][4] + $coef1['versa'][4] + $coef2['obverse'][4] + $coef2['versa'][4]
            + $coef1['obverse'][ASC] + $coef1['versa'][ASC] + $coef2['obverse'][ASC] + $coef2['versa'][ASC]
            + $coef1['obverse'][MC] + $coef1['versa'][MC] + $coef2['obverse'][MC] + $coef2['versa'][MC];

        foreach ($planets2 as $i => $pl)
        {
            if ($i < 5 || $i == ASC || $i == MC)
            {
                $sum = $coef1['obverse'][$i] + $coef1['versa'][$i] + $coef2['obverse'][$i] + $coef2['versa'][$i];
                // 20190104 Division by zero问题处理
                if ($sum == 0 || $total == 0 || $this->param['base'][$i] == 0) break;

                $a = $sum / $total * 7 * $this->param['base'][$i];
                if ($sum)
                {
                    $scale1 = ($coef1['obverse'][$i] + $coef2['obverse'][$i]) / $sum;
                    $scale2 = ($coef1['versa'][$i] + $coef2['versa'][$i]) / $sum;

                    $ret[0] += $scale1 * $a;
                    $ret[1] += $scale2 * $a;
                }

            }
        }

        $d = [0, 0, 0, 0, 0, 0, 0, 0];
        for ($k = 0; $k < 10; $k++)
        {
            if (!empty($planets1[$k]['phase']))
            {
//                $is_main_060120_1 = false;
                foreach ($planets1[$k]['phase'] as $phase)
                {
                    $a = $b = $c = 0;
                    if ($phase['phase_orb'] < 0.5) $phase_o = 1;
                    elseif ($phase['phase_orb'] < 1.5) $phase_o = 0.9;
                    elseif ($phase['phase_orb'] < 3) $phase_o = 0.85;
                    elseif ($phase['phase_orb'] <= 5) $phase_o = 0.8;
                    else $phase_o = 0.75;

                    if (in_array($k, [7, 8, 9]) || in_array($phase['id'], [7, 8, 9]))
                    {
                        if ($phase['phase_orb'] < 0.5) $phase_o = 1;
                        elseif ($phase['phase_orb'] < 1) $phase_o = 0.9;
                        elseif ($phase['phase_orb'] < 2) $phase_o = 0.7;
                        elseif ($phase['phase_orb'] <= 3) $phase_o = 0.4;
                        else $phase_o = 0.1;
                    }
                    // 凶星刑冲合主星
                    if ($k < 5 && in_array($phase['id'], [4, 6, 7, 8, 9]))
                    {
                        $infortune = [4 => 7, 6 => 15, 7 => 3, 8 => 2, 9 => 2];
                        $main = [10, 15, 7, 8, 5];
                        $phase_base = [0 => 0.2, 90 => 0.7, 180 => 0.4];
//                        if (in_array($phase['id'], [0, 1, 3, 5]) && $phase['phase_orb'] <= 2 && in_array($phase['phase_e'], [0, 60, 120]))
//                        {
//                            $is_main_060120_1 = true;
//                        }
                        if (in_array($phase['phase_e'], [0, 90, 180]))
                        {
                            $a = $infortune[$phase['id']];
                            $b = $main[$k];
                            $c = $phase_base[$phase['phase_e']];
                            if ($k == $this->option['data1'][1]['houses'][1]['protect_id']
                                || $k == $this->option['data1'][1]['houses'][1]['protect_ancient_id'])
                            {
                                $b += 3;
                            }
                            $d[0] += ($a + $b) * $c * $phase_o;
                        }
                    } // 凶星刑冲合轴点
                    elseif (in_array($k, [4, 6, 7, 8, 9]) && in_array($phase['id'], [ASC, MC]))
                    {
                        $infortune = [4 => 12, 6 => 8, 7 => 8, 8 => 5, 9 => 3];
                        $pivot = [ASC => 15, MC => 14];
                        $phase_base = [0 => 0.8, 90 => 0.2, 180 => 0.6];
                        if (in_array($phase['phase_e'], [0, 90, 180]))
                        {
                            $a = $infortune[$k];
                            $b = $pivot[$phase['id']];
                            $c = $phase_base[$phase['phase_e']];
                            $d[1] += ($a + $b) * $c * $phase_o;
                        }
                    } // 主星相互刑冲
                    elseif ($k < 4 && in_array($phase['id'], [0, 1, 2, 3]))
                    {
                        $main = [14, 16, 7, 10];
                        $phase_base = [90 => 0.35, 180 => 0.1];
                        if (in_array($phase['phase_e'], [90, 180]))
                        {
                            $a = $main[$k];
                            $b = $main[$phase['id']];
                            $c = $phase_base[$phase['phase_e']];
                            $d[2] += ($a + $b) * $c * $phase_o;
                        }
                    } // 主星刑四轴
                    elseif ($k < 4 && in_array($phase['id'], [ASC, MC]))
                    {
                        $main = [14, 16, 7, 10];
                        $pivot = [ASC => 16, MC => 15];
                        $phase_base = [90 => 0.2];
                        if ($phase['phase_e'] == 90)
                        {
                            $a = $main[$k];
                            $b = $pivot[$phase['id']];
                            $c = $phase_base[$phase['phase_e']];
                            $d[3] += ($a + $b) * $c * $phase_o;
                        }
                    }
                }
//                if ($is_main_060120_1 === false)
//                {
////                    $d[0] *= 1.3;
//                }
            }
//            if(!empty($planets2[$k]['phase']))
//            {
//                $is_main_060120_2 = false;
//                foreach ($planets2[$k]['phase'] as $phase)
//                {
//                    $a=$b=$c=0;
//                    if($phase['phase_orb'] < 0.5) $phase_o = 1;
//                    elseif($phase['phase_orb'] < 1.5) $phase_o = 0.9;
//                    elseif($phase['phase_orb'] < 3) $phase_o = 0.85;
//                    elseif($phase['phase_orb'] <= 5) $phase_o = 0.8;
//                    elseif($phase['phase_orb'] > 5) $phase_o = 0.75;
//
//                    if(in_array($k,[7,8,9]) || in_array($phase['id'],[7,8,9]))
//                    {
//                        if($phase['phase_orb'] < 0.5) $phase_o = 1;
//                        elseif($phase['phase_orb'] < 1) $phase_o = 0.9;
//                        elseif($phase['phase_orb'] < 2) $phase_o = 0.7;
//                        elseif($phase['phase_orb'] <= 3) $phase_o = 0.4;
//                        elseif($phase['phase_orb'] > 3) $phase_o = 0.1;
//                    }
//                    // 凶星刑冲合主星
//                    if($k < 5 && in_array($phase['id'],[4,6,7,8,9]))
//                    {
//                        $infortune = [4=>7,6=>15,7=>3,8=>2,9=>2];
//                        $main = [10,15,7,8,5];
//                        $phase_base = [0=>0.2,90=>0.7,180=>0.4];
//                        if(in_array($phase['id'],[0,1,3,5]) && $phase['phase_orb'] <= 2 && in_array($phase['phase_e'],[0,60,120]))
//                        {
//                            $is_main_060120_2 = true;
//                        }
//                        if(in_array($phase['phase_e'],[0,90,180]))
//                        {
//                            $a = $infortune[$phase['id']];
//                            $b = $main[$k];
//                            $c = $phase_base[$phase['phase_e']];
//                            if($k == $data1->details1['houses'][1]['protect_id']
//                                || $k == $data1->details1['houses'][1]['protect_ancient_id'])
//                            {
//                                $b += 3;
//                            }
//                            $d[4] += ($a+$b)*$c*$phase_o;
//                        }
//                    }
//                    // 凶星刑冲合轴点
//                    elseif(in_array($k,[4,6,7,8,9]) && in_array($phase['id'],[ASC,MC]))
//                    {
//                        $infortune = [4=>12,6=>8,7=>8,8=>5,9=>3];
//                        $pivot = [ASC=>15,MC=>14];
//                        $phase_base = [0=>0.8,90=>0.2,180=>0.6];
//                        if(in_array($phase['phase_e'],[0,90,180]))
//                        {
//                            $a = $infortune[$k];
//                            $b = $pivot[$phase['id']];
//                            $c = $phase_base[$phase['phase_e']];
//                            $d[5] += ($a+$b)*$c*$phase_o;
//                        }
//                    }
//                    // 主星相互刑冲
//                    elseif($k < 4 && in_array($phase['id'],[0,1,2,3]))
//                    {
//                        $main = [14,16,7,10];
//                        $phase_base = [90=>0.35,180=>0.1];
//                        if(in_array($phase['phase_e'],[90,180]))
//                        {
//                            $a = $main[$k];
//                            $b = $main[$phase['id']];
//                            $c = $phase_base[$phase['phase_e']];
//                            $d[6] += ($a+$b)*$c*$phase_o;
//                        }
//                    }
//                    // 主星刑四轴
//                    elseif($k < 4 && in_array($phase['id'],[ASC,MC]))
//                    {
//                        $main = [14,16,7,10];
//                        $pivot = [ASC=>16,MC=>15];
//                        $phase_base = [90=>0.2];
//                        if($phase['phase_e'] == 90)
//                        {
//                            $a = $main[$k];
//                            $b = $pivot[$phase['id']];
//                            $c = $phase_base[$phase['phase_e']];
//                            $d[7] += ($a+$b)*$c*$phase_o;
//                        }
//                    }
//                }
//                if($is_main_060120_2 === false)
//                {
////                    $d[4] *= 1.3;
//                }
//            }
        }


        $ts = array_sum($ret);
        if ($ts === 0)
        {
            return [50, 50];
        }
        if ($ret[0] === 0)
        {
            $harmonious = 0;
        } else
        {
            $harmonious = round($ret[0] / $ts * 100);
        }
        if ($ret[1] === 0)
        {
            $conflict = 0;
        } else
        {
            $conflict = round($ret[1] / $ts * 100);
        }

        $result = [$harmonious, $conflict];

        $this->data['harmoniousConflict'] = $result;
        return;
    }

    /**
     * 获取宫位增益能量和破坏能量
     * @return array
     */
    protected function getTheHousePower()
    {
        $planets1 = $this->option['data1'][1]['planets'];
        $planets1_2 = $this->option['data1'][0]['planets'];
        $planets2 = $this->option['data2'][1]['planets'];
        $planets2_2 = $this->option['data2'][0]['planets'];
        $good = [0 => 20, 1 => 20, 2 => 9, 3 => 12, 4 => 10, 5 => 12, 6 => 2, 7 => 2, 8 => 2, 9 => 2, 12 => 3];// 增益能量
        $bad = [4 => 4, 6 => 6, 7 => 1, 8 => 2, 9 => 1];// 破坏能量
        $hg = [1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0];// 宫位增益能量
        $hb = [1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0];// 宫位破坏能量
        // 日月水金火木土天海冥
        for ($i = 0; $i < 13; $i++)
        {
            if ($i > 9 && $i < 12) continue;
            if (!isset($planets1[$i])) continue;
            $planet1 = $planets1[$i];// A在B A
            $planet2 = $planets2[$i];// B在A B

            if (!empty($planet1['phase']))
            {
                $phase0_num = 0;
                $first = 8;
                $second = 8;
                $h_f = NULL;
                $h_s = NULL;
                $h = $h2 = NULL;
                foreach ($planet1['phase'] as $phase)
                {
                    if (!in_array($phase['id'], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, ASC, MC])) continue;
                    if ($phase['id'] == ASC)
                    {
                        // 合上升
                        if ($phase['phase_e'] == 0)
                        {
                            if (isset($good[$i])) $hg[1] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[1] += $bad[$i] + 15;
                        } // 合下降
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (isset($good[$i])) $hg[7] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[7] += $bad[$i] + 15;
                        }
                    } elseif ($phase['id'] == MC)
                    {
                        // 合天顶
                        if ($phase['phase_e'] == 0)
                        {
                            if (isset($good[$i])) $hg[10] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[10] += $bad[$i] + 15;
                        } // 合天底
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (isset($good[$i])) $hg[4] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[4] += $bad[$i] + 15;
                        }
                    } else
                    {
                        // 容许系数
                        $_orb = $phase['phase_orb'];
                        if ($_orb < 0.5) $o = 1;
                        elseif ($_orb < 1.5) $o = 0.9;
                        elseif ($_orb < 3) $o = 0.85;
                        elseif ($_orb <= 5) $o = 0.8;
                        else $o = 0.75;
                        $h = $planet1['in_house_id'];// 外盘星体落在底盘中的宫位
                        $h2 = $planets1_2[$phase['id']]['in_house_id'];// 底盘星体所在宫位
                        // 若与内盘某星成合相，该宫位增益能量或破坏能量+相应的外盘星体基本能量*容许系数
                        // （多颗星则以最紧密的相位计算，再加上次紧密的相位的一半）
                        if ($phase['phase_e'] == 0)
                        {
                            $phase0_num++;
                            if ($phase0_num == 0)
                            {
                                $first = $o;
                                $h_f = $h2;
                            } elseif ($o < $first)
                            {
                                $second = $first;
                                $first = $o;
                                $h_s = $h_f;
                                $h_f = $h2;
                            } elseif ($o > $first && $o < $second)
                            {
                                $second = $o;
                                $h_s = $h2;
                            }
                        }
                        // 若与内盘星体成六分相，检测成相星体所在宫位，该宫位增益能量+相应的外盘星体基本能量*容许系数*0.5（无破坏）
                        // 外盘星体所在宫位的增益能量+成相星体的基本能量*容许系数*0.5
                        elseif ($phase['phase_e'] == 60)
                        {
                            if (isset($good[$i])) $hg[$h2] += $good[$i] * $o * 0.5;
                            if (isset($good[$phase['id']])) $hg[$h] += $good[$phase['id']] * $o * 0.5;
                        }
                        // 若与内盘星体成四分相，分两种情况计算
                        // 1、   若外盘星体为火土天海冥（对双方都是天海冥的相位不予计算），对内盘成相星体宫位造成的破坏为
                        //  外盘星基本破坏能量*容许系数*2
                        // 2、   若外盘星体为日月水金木，对内盘成相星体宫位造成的
                        // 破坏为 外盘星基本增益能量*容许系数*0.3；
                        // 增益为 外盘星基本增益能量*容许系数*0.1
                        // 【对外盘星所在宫位的破坏，也按上述步骤计算】
                        elseif ($phase['phase_e'] == 90)
                        {
                            if (in_array($i, [4, 6, 7, 8, 9]))
                            {
                                if (in_array($i, [7, 8, 9]) && in_array($phase['id'], [7, 8, 9])) continue;
                                if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $o * 2;
                            } elseif (in_array($i, [0, 1, 2, 3, 5]))
                            {
                                if (isset($good[$phase['id']])) $hg[$h2] += $good[$phase['id']] * $o * 0.1;
                                if (isset($good[$phase['id']])) $hb[$h2] += $good[$phase['id']] * $o * 0.3;
                            }
                        }
                        // 若与内盘星体成三分相，检测成相星体所在宫位，该宫位增益能量+相应的外盘星体基本能量*容许系数*0.6（无破坏）
                        // 外盘星体所在宫位的增益能量+成相星体的基本能量*容许系数*0.6
                        elseif ($phase['phase_e'] == 120)
                        {
                            if (isset($good[$i])) $hg[$h2] += $good[$i] * $o * 0.6;
                            if (isset($good[$phase['id']])) $hg[$h] += $good[$phase['id']] * $o * 0.6;
                        }
                        // 若与内盘星体成对分相，分两种情况计算
                        // 1、   若外盘星体为火土天海冥（对双方都是天海冥的相位不予计算），对内盘成相星体宫位造成的破坏为
                        // 外盘星基本破坏能量*容许系数*1.5
                        // 2、   若外盘星体为日月水金木，对内盘成相星体宫位造成的
                        // 破坏为 外盘星基本增益能量*容许系数*0.25；
                        // 增益为 外盘星基本增益能量*容许系数*0.6
                        //【对外盘星所在宫位的破坏，也按上述步骤计算】
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (in_array($i, [4, 6, 7, 8, 9]))
                            {
                                if (in_array($i, [7, 8, 9]) && in_array($phase['id'], [7, 8, 9])) continue;
                                if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $o * 2;
                            } elseif (in_array($i, [0, 1, 2, 3, 5]))
                            {
                                if (isset($good[$phase['id']])) $hg[$h2] += $good[$phase['id']] * $o * 0.6;
                                if (isset($good[$phase['id']])) $hb[$h2] += $good[$phase['id']] * $o * 0.25;
                            }
                        }
                    }
                }
                if ($phase0_num == 1)
                {
                    if (isset($good[$i])) $hg[$h2] += $good[$i] * $first;
                    if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $first;
                } elseif ($phase0_num > 1)
                {
                    if (isset($good[$i])) $hg[$h2] += $good[$i] * $first + $good[$i] * $second * 0.5;
                    if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $first + $bad[$i] * $second * 0.5;
                }
            }

            if (!empty($planet2['phase']))
            {
                $phase0_num = 0;
                $first = 8;
                $second = 8;
                $h_f = NULL;
                $h_s = NULL;
                $h = $h2 = NULL;
                foreach ($planet2['phase'] as $phase)
                {
                    if (!in_array($phase['id'], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, ASC, MC])) continue;
                    if ($phase['id'] == ASC)
                    {
                        // 合上升
                        if ($phase['phase_e'] == 0)
                        {
                            if (isset($good[$i])) $hg[1] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[1] += $bad[$i] + 15;
                        } // 合下降
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (isset($good[$i])) $hg[7] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[7] += $bad[$i] + 15;
                        }
                    } elseif ($phase['id'] == MC)
                    {
                        // 合天顶
                        if ($phase['phase_e'] == 0)
                        {
                            if (isset($good[$i])) $hg[10] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[10] += $bad[$i] + 15;
                        } // 合天底
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (isset($good[$i])) $hg[4] += $good[$i] + 15;
                            if (isset($bad[$i])) $hb[4] += $bad[$i] + 15;
                        }
                    } else
                    {
                        // 容许系数
                        $_orb = $phase['phase_orb'];
                        if ($_orb < 0.5) $o = 1;
                        elseif ($_orb < 1.5) $o = 0.9;
                        elseif ($_orb < 3) $o = 0.85;
                        elseif ($_orb <= 5) $o = 0.8;
                        else $o = 0.75;
                        $h = $planet2['in_house_id'];// 外盘星体落在底盘中的宫位
                        $h2 = $planets2_2[$phase['id']]['in_house_id'];// 底盘星体所在宫位
                        // 若与内盘某星成合相，该宫位增益能量或破坏能量+相应的外盘星体基本能量*容许系数
                        // （多颗星则以最紧密的相位计算，再加上次紧密的相位的一半）
                        if ($phase['phase_e'] == 0)
                        {
                            $phase0_num++;
                            if ($phase0_num == 0)
                            {
                                $first = $o;
                                $h_f = $h2;
                            } elseif ($o < $first)
                            {
                                $second = $first;
                                $first = $o;
                                $h_s = $h_f;
                                $h_f = $h2;
                            } elseif ($o > $first && $o < $second)
                            {
                                $second = $o;
                                $h_s = $h2;
                            }
                        }
                        // 若与内盘星体成六分相，检测成相星体所在宫位，该宫位增益能量+相应的外盘星体基本能量*容许系数*0.5（无破坏）
                        // 外盘星体所在宫位的增益能量+成相星体的基本能量*容许系数*0.5
                        elseif ($phase['phase_e'] == 60)
                        {
                            if (isset($good[$i])) $hg[$h2] += $good[$i] * $o * 0.5;
                            if (isset($good[$phase['id']])) $hg[$h] += $good[$phase['id']] * $o * 0.5;
                        }
                        // 若与内盘星体成四分相，分两种情况计算
                        // 1、   若外盘星体为火土天海冥（对双方都是天海冥的相位不予计算），对内盘成相星体宫位造成的破坏为
                        //  外盘星基本破坏能量*容许系数*2
                        // 2、   若外盘星体为日月水金木，对内盘成相星体宫位造成的
                        // 破坏为 外盘星基本增益能量*容许系数*0.3；
                        // 增益为 外盘星基本增益能量*容许系数*0.1
                        // 【对外盘星所在宫位的破坏，也按上述步骤计算】
                        elseif ($phase['phase_e'] == 90)
                        {
                            if (in_array($i, [4, 6, 7, 8, 9]))
                            {
                                if (in_array($i, [7, 8, 9]) && in_array($phase['id'], [7, 8, 9])) continue;
                                if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $o * 2;
                            } elseif (in_array($i, [0, 1, 2, 3, 5]))
                            {
                                if (isset($good[$phase['id']])) $hg[$h2] += $good[$phase['id']] * $o * 0.1;
                                if (isset($good[$phase['id']])) $hb[$h2] += $good[$phase['id']] * $o * 0.3;
                            }
                        }
                        // 若与内盘星体成三分相，检测成相星体所在宫位，该宫位增益能量+相应的外盘星体基本能量*容许系数*0.6（无破坏）
                        // 外盘星体所在宫位的增益能量+成相星体的基本能量*容许系数*0.6
                        elseif ($phase['phase_e'] == 120)
                        {
                            if (isset($good[$i])) $hg[$h2] += $good[$i] * $o * 0.6;
                            if (isset($good[$phase['id']])) $hg[$h] += $good[$phase['id']] * $o * 0.6;
                        }
                        // 若与内盘星体成对分相，分两种情况计算
                        // 1、   若外盘星体为火土天海冥（对双方都是天海冥的相位不予计算），对内盘成相星体宫位造成的破坏为
                        // 外盘星基本破坏能量*容许系数*1.5
                        // 2、   若外盘星体为日月水金木，对内盘成相星体宫位造成的
                        // 破坏为 外盘星基本增益能量*容许系数*0.25；
                        // 增益为 外盘星基本增益能量*容许系数*0.6
                        //【对外盘星所在宫位的破坏，也按上述步骤计算】
                        elseif ($phase['phase_e'] == 180)
                        {
                            if (in_array($i, [4, 6, 7, 8, 9]))
                            {
                                if (in_array($i, [7, 8, 9]) && in_array($phase['id'], [7, 8, 9])) continue;
                                if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $o * 2;
                            } elseif (in_array($i, [0, 1, 2, 3, 5]))
                            {
                                if (isset($good[$phase['id']])) $hg[$h2] += $good[$phase['id']] * $o * 0.6;
                                if (isset($good[$phase['id']])) $hb[$h2] += $good[$phase['id']] * $o * 0.25;
                            }
                        }
                    }
                }
                if ($phase0_num == 1)
                {
                    if (isset($good[$i])) $hg[$h2] += $good[$i] * $first;
                    if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $first;
                } elseif ($phase0_num > 1)
                {
                    if (isset($good[$i])) $hg[$h2] += $good[$i] * $first + $good[$i] * $second * 0.5;
                    if (isset($bad[$i])) $hb[$h2] += $bad[$i] * $first + $bad[$i] * $second * 0.5;
                }
            }
        }
        return [$hg, $hb];
    }
}
